package com.google.code.struts2jruby;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.inject.Inject;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.jruby.Ruby;

public class JRubyResult extends ServletDispatcherResult {

    protected JRubyObjectFactory objectFactory;

    public JRubyResult() {
    }

    public JRubyResult(String location) {
        super(location);
    }

    public void doExecute(String location, ActionInvocation invocation) throws Exception {
        String result = invocation.getResultCode();
        Ruby ruby = (Ruby) objectFactory.getRuntime();
    }

    @Inject
    protected void setObjectFactory(ObjectFactory objectFactory) {
        if (objectFactory instanceof JRubyObjectFactory)
            this.objectFactory = (JRubyObjectFactory) objectFactory;
        else
            throw new RuntimeException("Sorry, the JRubyResult works with the RubyObjectFactory.");
    }

}
